﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.PlayerPrefs
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System.Runtime.CompilerServices;
using UnityEngine.Bindings;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>PlayerPrefs is a class that stores Player preferences between game sessions. It can store string, float and integer values into the user’s platform registry.</para>
  /// </summary>
  [NativeHeader("Runtime/Utilities/PlayerPrefs.h")]
  public class PlayerPrefs
  {
    [NativeMethod("SetInt")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool TrySetInt(string key, int value);

    [NativeMethod("SetFloat")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool TrySetFloat(string key, float value);

    [NativeMethod("SetString")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool TrySetSetString(string key, string value);

    /// <summary>
    ///   <para>Sets a single integer value for the preference identified by the given key. You can use PlayerPrefs.GetInt to retrieve this value.</para>
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    public static void SetInt(string key, int value)
    {
      if (!PlayerPrefs.TrySetInt(key, value))
        throw new PlayerPrefsException("Could not store preference value");
    }

    /// <summary>
    ///   <para>Returns the value corresponding to key in the preference file if it exists.</para>
    /// </summary>
    /// <param name="key"></param>
    /// <param name="defaultValue"></param>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern int GetInt(string key, int defaultValue);

    /// <summary>
    ///   <para>Returns the value corresponding to key in the preference file if it exists.</para>
    /// </summary>
    /// <param name="key"></param>
    /// <param name="defaultValue"></param>
    public static int GetInt(string key) => PlayerPrefs.GetInt(key, 0);

    /// <summary>
    ///   <para>Sets the float value of the preference identified by the given key. You can use PlayerPrefs.GetFloat to retrieve this value.</para>
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    public static void SetFloat(string key, float value)
    {
      if (!PlayerPrefs.TrySetFloat(key, value))
        throw new PlayerPrefsException("Could not store preference value");
    }

    /// <summary>
    ///   <para>Returns the value corresponding to key in the preference file if it exists.</para>
    /// </summary>
    /// <param name="key"></param>
    /// <param name="defaultValue"></param>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern float GetFloat(string key, float defaultValue);

    /// <summary>
    ///   <para>Returns the value corresponding to key in the preference file if it exists.</para>
    /// </summary>
    /// <param name="key"></param>
    /// <param name="defaultValue"></param>
    public static float GetFloat(string key) => PlayerPrefs.GetFloat(key, 0.0f);

    /// <summary>
    ///   <para>Sets a single string value for the preference identified by the given key. You can use PlayerPrefs.GetString to retrieve this value. </para>
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    public static void SetString(string key, string value)
    {
      if (!PlayerPrefs.TrySetSetString(key, value))
        throw new PlayerPrefsException("Could not store preference value");
    }

    /// <summary>
    ///   <para>Returns the value corresponding to key in the preference file if it exists.</para>
    /// </summary>
    /// <param name="key"></param>
    /// <param name="defaultValue"></param>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern string GetString(string key, string defaultValue);

    /// <summary>
    ///   <para>Returns the value corresponding to key in the preference file if it exists.</para>
    /// </summary>
    /// <param name="key"></param>
    /// <param name="defaultValue"></param>
    public static string GetString(string key) => PlayerPrefs.GetString(key, "");

    /// <summary>
    ///   <para>Returns true if the given key exists in PlayerPrefs, otherwise returns false.</para>
    /// </summary>
    /// <param name="key"></param>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern bool HasKey(string key);

    /// <summary>
    ///   <para>Removes the given key from the PlayerPrefs. If the key does not exist, DeleteKey has no impact.</para>
    /// </summary>
    /// <param name="key"></param>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern void DeleteKey(string key);

    /// <summary>
    ///   <para>Removes all keys and values from the preferences. Use with caution.</para>
    /// </summary>
    [NativeMethod("DeleteAllWithCallback")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern void DeleteAll();

    /// <summary>
    ///   <para>Saves all modified preferences.</para>
    /// </summary>
    [NativeMethod("Sync")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern void Save();

    [StaticAccessor("EditorPrefs", StaticAccessorType.DoubleColon)]
    [NativeMethod("SetInt")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    internal static extern void EditorPrefsSetInt(string key, int value);

    [NativeMethod("GetInt")]
    [StaticAccessor("EditorPrefs", StaticAccessorType.DoubleColon)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    internal static extern int EditorPrefsGetInt(string key, int defaultValue);
  }
}
